package com.wn.inventory.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.ActivitiStartEntity;
import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Hr;
import com.wn.entity.ProductInWarehouseApplication;
import com.wn.inventory.feign.ActivitiFeignClient;
import com.wn.inventory.mapper.ProductInWarehouseApplicationMapper;
import com.wn.inventory.service.ProductInWarehouseApplicationService;
import com.wn.inventory.vo.ProductInWarehouseApplicationVo;
import com.wn.utils.CurrentTime;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ author     ：NST
 * @ date       ：Created in 2022/10/20 15:34
 * @ description：生产工单入库Impl
 * @ modified By：
 * @ version:
 */
@Service
public class ProductInWarehouseApplicationImpl implements ProductInWarehouseApplicationService {
    @Autowired
    ProductInWarehouseApplicationMapper productInWarehouseApplicationMapper;
    @Autowired
    ActivitiFeignClient activitiFeignClient;
    /**
     * @param productInWarehouseApplication
     * @return void
     * @ author nst
     * @ date 2022/10/20 15:47
     * @ Description 增加生产工单入库信息
     */
    @Override
    public void insert(ProductInWarehouseApplication productInWarehouseApplication, HttpServletRequest request) {
        productInWarehouseApplication.setApplicant(new Hr(Integer.parseInt(request.getHeader("userId"))));
        productInWarehouseApplication.setInWarehouseTime(CurrentTime.getCurrentTime());
        String identifier="PROIWA"+CurrentTime.getCurrentTimeString();
        productInWarehouseApplication.setIdentifier(identifier);
        ResponseEntity<String> entity = activitiFeignClient.startInstance(new ActivitiStartEntity("in_warehouss_application_id", "user1", request.getHeader("userWorkNumber")));
//        activitiFeignClient.completeTask(new ActivitiCompleteEntity("in_warehouss_application_id",entity.getData(),"user1",));
        productInWarehouseApplication.setActivitiInstanceId(entity.getData());
        productInWarehouseApplicationMapper.insert(productInWarehouseApplication);
    }
    /**
     * @param product
     * @return com.wn.common.PageBean<com.wn.entity.ProductInWarehouseApplication>
     * @ author nst
     * @ date 2022/10/20 17:44
     * @ Description 多条件分页查询生产工单入库申请表信息
     */
    @Override
    public PageBean<ProductInWarehouseApplication> getByCondition(ProductInWarehouseApplicationVo product) {
        Page<ProductInWarehouseApplication> page = PageHelper.startPage(product.getCurrPage(), product.getPageSize());
        List<ProductInWarehouseApplication> list = productInWarehouseApplicationMapper.getByCondition(product.getProductInWarehouseApplication());
        return PageBeanUtil.getPageBean(list,page,product.getCurrPage(),product.getPageSize());
    }
}
